﻿

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Globalization;

namespace Ogdi.Data.DataLoader
{
    [Serializable]
    public class TimeZoneNotFoundException : Exception
    {
        public TimeZoneNotFoundException(String timeZoneName)
            : base(constructMessage(timeZoneName))
        {
        }

        private static string constructMessage(String timeZoneName)
        {
            string text = "TimeZone '" + timeZoneName + "' not found. Use one of:" + System.Environment.NewLine;
            var timeZones = TimeZoneInfo.GetSystemTimeZones();
            var zones = new List<TimeZoneInfo>();
            foreach (var t in timeZones)
                zones.Add(t);
            zones.Sort(delegate(TimeZoneInfo z1, TimeZoneInfo z2) { return z1.BaseUtcOffset.Hours.CompareTo(z2.BaseUtcOffset.Hours); });
            foreach (var t in zones)
                text += t.DisplayName.Replace("&","&amp;") + System.Environment.NewLine;
            return text;
        }
    }
}
